package com.example.pro1.controller.zhao;

import com.example.pro1.service.zhao.alipay.AliPayService;
import com.example.pro1.valu.R;
import com.example.pro1.valu.Standard;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;


@CrossOrigin//开放前端跨域访问
@Api(tags = "支付宝支付")
@RestController
@RequestMapping("/api/ali-pay")
@Slf4j
public class AliPayController {
    @Resource
    private AliPayService aliPayService;

    @PostMapping("/native")
    public Standard Native(@RequestParam("productId") long productId,@RequestParam("userId") long userId,@RequestParam("fee") Integer fee,@RequestParam("numm") String num,@RequestParam("beizhu") String beizhu,@RequestParam("addressId") String addressId)
    {
        log.info("发起支付请求");
        //返回二维码连接 and订单号
        Map<String,Object> map= null;
        try {
            map = aliPayService.nativePay(productId,"支付宝",userId,fee,num,beizhu,addressId);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return R.ok().setData(map);
    }
}
